#ifndef GAMEWIDGET_H
#define GAMEWIDGET_H

#include<QWidget>
#include<QTimer>
#include<QKeyEvent>
#include<QLabel>
#include<QPushButton>
#include<QVBoxLayout>
#include<QGraphicsScene>
#include<QGraphicsView>
#include<QGraphicsPixmapItem>
#include<QVector>
#include<QPainter>

class GameWidget:public QWidget
{
    Q_OBJECT

public:
    explicit GameWidget(QWidget *parent=nullptr);
    void startGame();
    void resumeGame();
    void returnToMenu();

signals:
    void gamePaused();
    void gameOver(bool win);

protected:
    void paintEvent(QPaintEvent *event)override;
    void keyPressEvent(QKeyEvent* event)override;


private:
    QGraphicsScene* scene;
    QGraphicsView* view;
    struct Position{
        int x;
        int y;
    };


    void mouseup();
    void updateGame();
    void moveMouse();
    bool isCatNearby(int mouseX,int mouseY);
    void checkCollision();
   // void setupScene();
    void isObstacleCollision(QGraphicsPixmapItem* item);

  //  QGraphicsPixmapItem* background;
   // QVector<QGraphicsPixmapItem*>obstacles;


    QTimer* gameTimer;
    QTimer* mouseTimer;
    QTimer* countdownTimer;
    QTimer* obstacle;
    int timeLeft;
    QLabel* timeLabel;

    Position cat;
    Position mouse;
    int catSize;
    int mouseSize;
    int gridSize;
    int catSpeed;
    int mouseSpeed;
    int mousefeel;
    bool firstcatched;
    bool paused;

    QString bglmagePath;

    QLabel* pauseLabel1;
    QPushButton* resumeButton1;
    QPushButton* menuButton1;
};

#endif//GAMEWIDGET_H
